<?php
namespace app\admin\logic\mqlogic;
use app\common\library\rabitmq\MqPublisherObject;
use PhpAmqpLib\Message as PM;


class DirectPublisher extends MqPublisherObject
{

    public function bind()
    {
        $this->channel->queue_bind($this->queue, $this->exchange, $this->bindKey);
    }
    /**
     * 延时队列
     */
    public function bindDelay($args = []) {
        $default = [
            "x-message-ttl" => ["I", 10000],
            "x-dead-letter-exchange" => ["S", "delay_exchange"],
            "x-dead-letter-routing-key" => ["S", "delay_queue"],
        ];
        $argsArr = array_merge($default, $args);

        $this->channel->queue_declare($this->queue,false,true,false,false,false,$argsArr);
        $this->channel->queue_bind($this->queue, $this->exchange, $this->bindKey);
    }
    public function publish($message, $config = null)
    {
        $objMessage = new PM\AMQPMessage($message);
        $this->channel->basic_publish($objMessage, $this->exchange, $this->bindKey);
    }

}